package XML.g2;

import java.io.File;
import java.util.Arrays;

import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class GenerateXML {

	/**
	 * @param args
	 * @throws JAXBException 
	 */
	public static void main(String[] args) throws JAXBException {
		
		Student s = new Student("Horst",123,"Informatik");
		
		JAXBContext context = JAXBContext.newInstance(Student.class);
		
		Marshaller m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		m.marshal(s, System.out);
		
		Student s2 = new Student("Babsi",234,"Kunst");
		University u = new University();
		u.setStudents(Arrays.asList(s,s2));
		
		JAXB.marshal(u,new File("university.xml"));
		University uni = JAXB.unmarshal(new File("university.xml"),University.class);
		
		System.out.println(uni.getStudents().get(1).getName());
		
	}

}
